package com.ruoyi.project.hr.controller;

import java.util.List;

import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.framework.security.LoginUser;
import com.ruoyi.framework.security.service.TokenService;
import com.ruoyi.project.system.domain.THrEmpInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.hr.domain.THrInfoEmploy;
import com.ruoyi.project.hr.service.ITHrInfoEmployService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 人员信息管理Controller
 *
 * @author lt
 * @date 2020-04-12
 */
@RestController
@RequestMapping("/hr/EMPLOY")
public class THrInfoEmployController extends BaseController
{
    @Autowired
    private ITHrInfoEmployService tHrInfoEmployService;

    @Autowired
    private TokenService tokenService;

    /**
     * 查询人员信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('hr:EMPLOY:list')")
    @GetMapping("/list")
    public TableDataInfo list(THrInfoEmploy tHrInfoEmploy)
    {
        startPage();
        List<THrInfoEmploy> list = tHrInfoEmployService.selectTHrInfoEmployList(tHrInfoEmploy);
        return getDataTable(list);
    }

    /**
     * 导出人员信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('hr:EMPLOY:export')")
    @Log(title = "人员信息管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(THrInfoEmploy tHrInfoEmploy)
    {
        List<THrInfoEmploy> list = tHrInfoEmployService.selectTHrInfoEmployList(tHrInfoEmploy);
        ExcelUtil<THrInfoEmploy> util = new ExcelUtil<THrInfoEmploy>(THrInfoEmploy.class);
        return util.exportExcel(list, "EMPLOY");
    }

    /**
     * 获取人员信息管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('hr:EMPLOY:query')")
    @GetMapping(value = "/{empId}")
    public AjaxResult getInfo(@PathVariable("empId") String empId)
    {
        return AjaxResult.success(tHrInfoEmployService.selectTHrInfoEmployById(empId));
    }

    /**
     * 新增人员信息管理
     */
    @PreAuthorize("@ss.hasPermi('hr:EMPLOY:add')")
    @Log(title = "人员信息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody THrInfoEmploy tHrInfoEmploy)
    {
        return toAjax(tHrInfoEmployService.insertTHrInfoEmploy(tHrInfoEmploy));
    }

    /**
     * 修改人员信息管理
     */
    @PreAuthorize("@ss.hasPermi('hr:EMPLOY:edit')")
    @Log(title = "人员信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody THrInfoEmploy tHrInfoEmploy)
    {
        return toAjax(tHrInfoEmployService.updateTHrInfoEmploy(tHrInfoEmploy));
    }

    /**
     * 删除人员信息管理
     */
    @PreAuthorize("@ss.hasPermi('hr:EMPLOY:remove')")
    @Log(title = "人员信息管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{empIds}")
    public AjaxResult remove(@PathVariable String[] empIds)
    {
        return toAjax(tHrInfoEmployService.deleteTHrInfoEmployByIds(empIds));
    }


    @Log(title = "入职流程导入", businessType = BusinessType.IMPORT)
//    @PreAuthorize("@ss.hasPermi('system:user:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<THrInfoEmploy> util = new ExcelUtil<THrInfoEmploy>(THrInfoEmploy.class);
        List<THrInfoEmploy> list = util.importExcel(file.getInputStream());
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        String operName = loginUser.getUsername();
        String message = tHrInfoEmployService.importUser(list, updateSupport, operName);
        return AjaxResult.success(message);
    }

    @GetMapping("/importTemplate")
    public AjaxResult importTemplate()
    {
        ExcelUtil<THrInfoEmploy> util = new ExcelUtil<THrInfoEmploy>(THrInfoEmploy.class);
        return util.importTemplateExcel("紧密型外包人员导入模板");
    }


}
